/**
 * @file microwave_module_test.c
 * @author Rocky
 * @brief 微波模块测试程序
 * @version 0.1
 * @date 2024-03-26
 *
 * @copyright Copyright (c) 2024
 *
 */
#include "microwave_module.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define PROGRAM_NAME "microwave_module_test"

static void showusage(void) {
    fprintf(stderr, "usage: %1$s <frequency> <attenuation>\n", PROGRAM_NAME);
    exit(EXIT_FAILURE);
}

int main(int argc, char *argv[]) {
    uint32_t freq;
    uint8_t attenuation;

    if (argc != 3)
        showusage();

    freq = strtoll(argv[1], NULL, 0);
    attenuation = strtoll(argv[2], NULL, 0);

    if (freq > 0) {
        // 微波模块上电，请等待
        printf("The microwave module is powering up, please wait......\n");
        microwave_module_init();
        sleep(1);

        set_microwave_rx_frequency(freq, attenuation);
        uint8_t rx[4];
        get_microwave_module_status(rx);
        printf("status: %02x\n", rx[1]);
        printf("frq code: %02d\n", rx[2]);
        printf("attenuation code: %02x\n", rx[3]);
        close_microwave_module();
    }

    if (freq == 0)
        microwave_module_power_off();

    return 0;
}
